package com.lx.api.weight;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lx.core.weight.entity.dto.GoodsTypeDTO;
import com.lx.core.weight.entity.dto.SettlementDTO;
import com.lx.core.weight.entity.vo.GoodsTypeVO;
import com.lx.core.weight.entity.vo.SettlementVO;
import com.lx.core.weight.service.GoodsTypeService;
import com.lx.core.weight.service.SettlementService;
import com.lx.core.weight.service.WeightUpdateService;
import com.lx.framework.common.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;

/**
 * @author lx
 * @date 2025/10/03 22:08
 **/
@RestController
@Api(tags = "货物类型管理")
@RequestMapping("/weight/goodsType")
public class GoodsTypeController {

    private final GoodsTypeService goodsTypeService;

    public GoodsTypeController(GoodsTypeService goodsTypeService) {

        this.goodsTypeService = goodsTypeService;
    }

    @ApiOperation(value = "获取货物列表分页")
    @ApiResponses(@ApiResponse(code = 200, message = "操作成功", response = SettlementVO.class))
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public R page(@RequestBody GoodsTypeDTO goodsTypeDTO) {
        IPage<GoodsTypeVO> page = new Page<>(goodsTypeDTO.getCurrent(), goodsTypeDTO.getSize());
        GoodsTypeVO goodsTypeVO = this.goodsTypeService.findGoodsTypePage(page, goodsTypeDTO);
        return R.success("操作成功", goodsTypeVO);
    }

    @ApiOperation(value = "删除货物")
    @ApiResponses(@ApiResponse(code = 200, message = "操作成功", response = SettlementVO.class))
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public R page(@PathVariable("id") Integer id) {
        Boolean result = this.goodsTypeService.deleteGoodsType(id);
        return R.success("操作成功", result);
    }

    @ApiOperation(value = "新增货物")
    @ApiResponses(@ApiResponse(code = 200, message = "操作成功"))
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public R add(@RequestParam String name, @RequestParam boolean prioritySelect) {
        return this.goodsTypeService.addGoodsType(name, prioritySelect);
    }

    @ApiOperation(value = "新增货物")
    @ApiResponses(@ApiResponse(code = 200, message = "操作成功"))
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public R edit(@PathVariable("id") Integer id, @RequestParam boolean prioritySelect) {
        return this.goodsTypeService.editGoodsType(id, prioritySelect);
    }

}
